Hello,
Skip s = create
Skip s = create
print "=> " (sizeof s) "\n"
put(s,0,0)
print "=> " (sizeof s) "\n"
put(s,0,0)
print "=> " (sizeof s) "\n"
put(s,0,0)
print "=> " (sizeof s) "\n"
put(s,0,0)
print "=> " (sizeof s) "\n"
delete s
SystemAdmin - Fri Nov 18 12:52:36 EST 2011 |
Re: Getting the element count in a skip list |
Re: Getting the element count in a skip list
The Skip object does not track its element count natively. If you what the know the count you would have to track it yourself every time you successfully add/delete an element or do a quick iteration through it to calculate the size.
int sizeOfAnySkip = 0;
int anyData;
for anyData in mySkipList do {
sizeOfAnySkip++;
}
|
Re: Getting the element count in a skip list Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: Getting the element count in a skip list Mathias Mamsch - Fri Nov 18 18:22:50 EST 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS This is what I feared... Well, probably the simplest is to count every time I put a new element, or delete an existing element. VBR, Vincent. |
Re: Getting the element count in a skip list SystemAdmin - Mon Nov 21 03:00:12 EST 2011 always ehan I use an Array or a Skip list, I have an element included which I use as a counter for the numbers of elements inside. Thus each time I'm using Array, the position 0 is reserved for the counter value. Code Pattern for this: Array arr = create(1,10); //add element int i = 0; for x in y do { put(arr, 0, 0, ++i); put(arr, 0, i, valOf(x)); } //read elements int nrOfArrElements = get(arr, 0, 0); //print "nrOfArrElements : " nrOfArrElements "\n"; if (nrOfArrElements >0) { int loopCounter; for loopCounter in 1 : nrOfArrElements do { TypeOfValue Value = (TypeCasting) get(arr, 0, loopCounter) } } Cheers, Helko |
Re: Getting the element count in a skip list SystemAdmin - Mon Nov 21 03:00:12 EST 2011 It seems "easier" to just count it when you need to:
int CountSkip(Skip in_skp)
{ int Count = 0
string Data
for Data in in_skp do
{ Count++
}
return(Count)
} // end CountSkip()
...
if (CountSkip(skpWhatever) > Threshold) then...
|
Re: Getting the element count in a skip list llandale - Mon Nov 21 15:45:28 EST 2011 It seems "easier" to just count it when you need to:
int CountSkip(Skip in_skp)
{ int Count = 0
string Data
for Data in in_skp do
{ Count++
}
return(Count)
} // end CountSkip()
...
if (CountSkip(skpWhatever) > Threshold) then...
Actually what I was trying to do is to use a Skip as some sort of stack. So the key is just the depth and duplicates are not possible. Maybe Skip are not the best type for stacks, I was thinking that a good old underlying Array would make it with some mechanism to relocate it when the sizes grows beyond the allocation. Anyhow that would means building my own use type "Stack", which might be a better approach for futureproofness. Vincent. |
Re: Getting the element count in a skip list SystemAdmin - Tue Nov 22 11:29:13 EST 2011
Skip skpStack = create()
int StackPointer = 0
void Push(string Value)
{ put(skpStack, ++StackPointer, Value)
}
string Pop()
{ string Value = ""
if (find(skpStack, StackPointer, Value)) StackPointer--
else Value = "" // Empty stack or error
return(Value)
}
Push("B")
Push("C")
Push("A")
Push("C")
Pop
string Value
int Position = 0
for Value in skpStack do
{ Position = (int key skpStack)
print Position "\t" Value "\n"
}
print StackPoint "\tStackOK = " (StackPointer == Position) "\n"
|